package com.example.userdome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.userdome.mapper.UserMapper;
import com.example.userdome.pojo.ServiceResponse;
import com.example.userdome.pojo.User;
import com.example.userdome.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public List<User> selectByAll(Integer id,String username,String password){
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        if (id!=null){
            queryWrapper.eq("id",id);
        }
        if (StringUtils.isNotBlank(username)){
            queryWrapper.like("username",username);
        }
        if (StringUtils.isNotBlank(password)){
            queryWrapper.like("password",password);
        }
        return userMapper.selectList(queryWrapper);
    }



    //判断密码和用户名是否为空
    @Override
    public User login(String username,String password){
        ServiceResponse serviceResponse=new ServiceResponse();
        if (StringUtils.isBlank(username)||StringUtils.isBlank(password)){
            serviceResponse.setResult(false);
            serviceResponse.setMsg("用户名和密码不能为空");
        }
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username).eq("password",password);
        return this.getOne(queryWrapper);
    }


}
